// pages/tmList/tmList.js
var common = require("../../utils/common.js");
//index.js
//获取应用实例
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
     show:true
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.setNavigationBarTitle({
      title: '客户列表'
    });
    this.getToken(options);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

    // var that=this;
    // common.ajaxPost(
    //   'portal/wlpUsers/queryUserInfo.action', {
    //     xcxOpenId: app.globalData.xcxOpenId,
    //     bid: app.globalData.bid
    //   },
    //   function (res) {
    //     if (res && res["result"]) {
    //       app.globalData.id = res.userInfo.id;
    //       that.queryImToken();
    //       that.queryImfriendList();
    //     }
    //   }
    // ) 
  },
  
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    app.globalData.isGoBack=true;
    app.globalData.isAuto = true;
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {
  //   wx.hideShareMenu()
  // },
  getUserInfo: function (options) {
    var that = this;
    common.ajaxPost(
      'portal/wlpUsers/queryUserInfo.action', {
        xcxOpenId: app.globalData.xcxOpenId,
        bid: app.globalData.bid,
        userType: 2
      },
      function (res) {
        if (res && res["result"]) {
          console.log("3564" + res);
          app.globalData.userInfo = res.userInfo;
          that.getToken(options);
        }
      }
    )
  },
  getToken: function (options) {
    var that = this;
    var GwHeadImage = options.GwHeadImage;
    var GwName = options.GwName;
    var GwUserType = options.GwUserType;
    var Gwid = options.Gwid;
    var bid=options.bid;
    
    common.ajaxPost(
      'portal/wlpRecord/queryImToken.action', {
        id: Gwid
      },
      function (res) {
        if (res && res["result"]) {
          console.log(res);
          var tromImToken = res.imToken;
          var urls = "https://px.diandianja.com/page2/ownerAdvisorCertifiAndIMList_wlp.html?GwHeadImage=" + GwHeadImage + "&GwName=" + encodeURI(GwName) + "&GwUserType=" + GwUserType +"&isXcx=1&bid="+bid+ "&Gwid=" + Gwid + "&tromImToken=" + tromImToken
 
          that.setData({
            urls: urls
          })
          console.log(urls);
          console.log(bid);
        }
      }
    )
  },



  queryImfriendList:function(){
    //获取用户信息列表
    var that=this;
    console.log(app);
    common.ajaxPostNo(
      'portal/wlpRecord/queryImfriendList.action', {
        id: app.globalData.id
      },
      function (res) {
        console.log(res)
        if (res && res.length > 0) {
            if(res.imFriendList<=0){
                that.setData({
                  show:true
                })
            }
        }
      }
    )
  }
})